<script>
export default {
  name: "TaskList",
  props:['groupId','gName'],
  created(){
    //初始化表格数据
    this.init_table_data();
  },
  data() {
    return {
      tableData: [],
      page: {
        pageNow: 1,
        pageSize: 7,
        total: 0,
        tj1:'',
        tj3:''
      },
      disable:true,
    }
  },
  methods:{
    //初始化表格数据
    async init_table_data(){
        const  _this = this;
        this.page.tj3 = this.groupId;
        const res = await this.$http.get("taskInfos/get_task_by_gropid",{params:this.page});
        this.tableData = res.data.data.records;

        this.page.total = res.data.data.total;
        setTimeout(function(){_this.disable=false},500);
    },

    del_row(row){
      this.$confirm('此操作将删除该任务, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () =>  {
        //确认删除
         const res = await this.$http.get('/tasks/del_task?tid='+row.tid+'&accId='+row.accId);
        if(res.data.data){
          this.$message.success("恭喜，删除成功！");
          //刷新页面
          this.init_table_data();
        }else{
          this.$message.error("删除失败！！！");
        }
      }).catch(() => {
        this.$message.error("已取消删除！！！");
      });
    },

    sizeChange(val){
      this.page.pageSize = val;
      this.init_table_data();
    },

    pageChange(val){
      this.page.pageNow = val;
      this.init_table_data();
    },

    back2group(){
      this.$emit("backtogroup");
    },
    canuse(row){
      return row.state == 2;
    }
  }
}
</script>

<template>
  <div>
    <!-------------------------------------------导航组件------------------------------------------------------------->
    <el-row>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item><a @click="back2group">任务列表</a></el-breadcrumb-item>
        <el-breadcrumb-item>{{ gName }}</el-breadcrumb-item>
      </el-breadcrumb>
    </el-row>
    <!-------------------------------------------搜索组件------------------------------------------------------------->
    <el-card class="box-card" style="margin-top: 20px">
      <el-row :gutter="20">



        <el-col :span="5" >
          <el-input  @keyup.native.enter="init_table_data" v-model="page.tj1"  placeholder="请输入姓名、电话" >
            <i class="el-icon-search" slot="suffix"  style="line-height: 40px" @click="init_table_data"></i>
          </el-input>
        </el-col>
        <el-col :span="9" :offset="Number(6)">
          <h2>{{ gName }}</h2>
        </el-col>
      </el-row>

      <!-------------------------------------------表格组件------------------------------------------------------------->
      <el-row style="margin-top: 20px">
        <el-table
            :data="tableData"
            border
            style="width: 100%">

          <el-table-column
              type="index"
              align="center"
              min-width="10">
          </el-table-column>

          <el-table-column
              prop="realName"
              label="姓名"
              align="center"
              min-width="12">
          </el-table-column>

          <el-table-column
              prop="phone"
              label="手机"
              align="center"
              min-width="18">
          </el-table-column>

          <el-table-column
              prop="groupName"
              label="任务名称"
              align="center"
              min-width="24">
          </el-table-column>

          <el-table-column
              prop="taskNo"
              label="任务编号"
              align="center"
              min-width="24">
          </el-table-column>



          <el-table-column
              prop="taskType"
              label="任务"
              align="center"
              min-width="20">
            <template slot-scope="scope">
                <span v-if="scope.row.taskType==1">任务一</span>
                <span v-if="scope.row.taskType==2">任务二</span>
                <span v-if="scope.row.taskType==3">任务三</span>
                <span v-if="scope.row.taskType==4">任务一</span>
                <span v-if="scope.row.taskType==5">任务二</span>
                <span v-if="scope.row.taskType==6">任务三</span>
                <span v-if="scope.row.taskType==7">任务四</span>
            </template>
          </el-table-column>


          <el-table-column
                  prop="pubTime"
                  label="发布日期"
                  align="center"
                  min-width="20"
          >
            <template slot-scope="scope">
              {{String(scope.row.pubTime).substr(0,10)}}
            </template>
          </el-table-column>

          <el-table-column
              prop="state"
              label="完成情况"
              align="center"
              min-width="20"
          >
            <template slot-scope="scope">
              <el-tag v-if="scope.row.state=='1'" effect="dark" type="primary" disable-transitions>进行中</el-tag>
              <el-tag v-if="scope.row.state=='2'" effect="dark" type="success" disable-transitions>已完成</el-tag>
            </template>
          </el-table-column>

          <el-table-column
              fixed="right"
              label="操作"
              align="center"
              min-width="15">
            <template slot-scope="scope">
              <el-button @click="back2group()" :disabled="disable" type="primary" size="small" icon="iconfont icon-fanhui2" circle></el-button>
              <el-button @click="del_row(scope.row)" :disabled="canuse(scope.row)" type="danger" icon="el-icon-delete" size="small" circle></el-button>
            </template>
          </el-table-column>
        </el-table>

        <!-------------------------------------------分页组件------------------------------------------------------------->
        <el-pagination
            @current-change="pageChange"
            @size-change="sizeChange"
            :current-page="page.pageNow"
            :page-sizes="[7, 15, 20]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            style="margin-top: 20px;float:right"
            :total="page.total">
        </el-pagination>

      </el-row>
    </el-card>
  </div>
</template>

<style scoped>

</style>